<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="/static/component/pear/css/pear.css" />
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
</head>
<body class="pear-container">
        <!--数据表开始-->
        <form class="layui-form" name="form-builder">
            <!---->
            {if $form_items}
            <div class="mainBox">
            <div class="main-container">
                        <!---->
                        {volist name="form_items" id="form"}
                        {switch form.type}
                        {case value="hidden"}
                        {// 隐藏域 }
                        {include file="form_builder/items/hidden" type='' /}
                        {/case}
                        {case text}
                        {// 单行文本框 }
                        {include file="form_builder/items/text" type='' /}
                        {/case}
                        {case value="textarea"}
                        {// 多行文本框 }
                        {include file="form_builder/items/textarea" type='' /}
                        {/case}
                        {case value="radio"}
                        {// 单选 }
                        {include file="form_builder/items/radio" type='' /}
                        {/case}
                        {case value="checkbox"}
                        {// 多选 }
                        {include file="form_builder/items/checkbox" type='' /}
                        {/case}

                        {case value="select"}
                        {// 下拉菜单 }
                        {include file="form_builder/items/select" type='' /}
                        {/case}


                        {default /}

                        {/switch}
                        {/volist}
                        <!---->
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                {php}if(isset($btn_hide) && !in_array('submit', $btn_hide)):{/php}
                                <button class="layui-btn " lay-submit lay-filter="add">{$btn_title['submit']|default='提
                                    交'}</button>
                                {php}endif;{/php}
                                {php}if(isset($btn_hide) && !in_array('back', $btn_hide)):{/php}

                                {php}endif;{/php}
                                {// 额外按钮}
                                {foreach $btn_extra as $key=>$vo }
                                {$vo|raw|default=''}
                                {/foreach}
                            </div>
                        </div>
                    </div>
                    <!-- /.box -->
              
            </div>
            {else /}
            <div class="row">
                <div class="col-sm-12 col-xs-12">
                    <div class="box box-body">
                        {$empty_tips|raw}
                    </div>
                    <!-- /.box -->
                </div>
            </div>
            {/if}
        </form>
<!--内容结束-->
<!--js逻辑-->
<script>



    layui.use(['form','jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;

        form.on('submit(add)', function(data){
        $.ajax({
            url:'{$form_url}',
            data:JSON.stringify(data.field),
            dataType:'json',
            contentType:'application/json',
            type:'post',
            success:function(res){
                //判断有没有权限
                if(res && res.code==999){
                    layer.msg(res.msg, {
                        icon: 5,
                        time: 2000, 
                    })
                    return false;
                }else if(res.code==1){
                    layer.msg(res.msg,{icon:1,time:1000},function(){
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        // parent.layui.table.reload("user-table");
                    });
                }else{
                    layer.msg(res.msg,{icon:2,time:1000});
                }
            }
        })
        return false;
    });
    });
</script>
</body>
</html>
